package org.example.user.http;

import org.example.user.api.UserApi;
import org.example.user.data.form.UserLoginForm;
import org.example.user.data.view.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserApi userApi;

    @RequestMapping("/login")
    public UserInfo login(
            @RequestBody @Validated UserLoginForm loginForm){

        UserInfo userInfo = userApi.loginUser(loginForm.getAccount(), loginForm.getPassword());

        return userInfo;

    }

}
